import wx

##class MyTimer(wx.PyTimer):
##	def __init__(self
class MyScrollPanel(wx.PyControl):
	def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
				 size=wx.DefaultSize, style=wx.NO_BORDER,
				 validator=wx.DefaultValidator, name="ScrollPanel"):
		wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name)
#		self.SetInitialSize(size)
		self.SetVirtualSize(size)
		self.SetSize((size[0]/2, size[1]))
		self.InheritAttributes()
		self.Bind(wx.EVT_PAINT, self.OnPaint)
		self.Bind(wx.EVT_TIMER, self.OnTimer)
		self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
		#self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
		#self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
		self.buffer = wx.EmptyBitmap(*size)
		self.offset = 0
		self.Draw()
	def OnEraseBackground(self, event):
		pass
	def OnPaint(self, event):
#		print "OnPaint!"
		dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA)
		dc.SetDeviceOrigin(self.offset, 0)
#		dc = wx.BufferedPaintDC(self)
#		self.Draw(dc)
	def Draw(self):
		print 'Draw', self
		dc = wx.BufferedDC(None, self.buffer, wx.BUFFER_VIRTUAL_AREA)
		brush = wx.Brush('blue', wx.SOLID)
		dc.SetBackground(brush)
		dc.Clear()
		dc.SetTextForeground('green')
		font = wx.Font(36, wx.ROMAN, wx.NORMAL, wx.NORMAL)
		dc.SetFont(font)
		dc.DrawText('This is my Foo Bar Blah', 5, 5)
	def Scroll(self, dir):
		self.incr = dir
		self.dest = self.offset + dir*90
		self.timer = wx.Timer(self, -1)
		self.timer.Start(10)
	def OnTimer(self, evt):
		self.offset += 3*self.incr
		self.Refresh()
		if self.offset == self.dest:
			self.timer.Stop()

class MyFrame(wx.Frame):

	def __init__(self, parent):
		wx.Frame.__init__(self, parent, -1, "GUI Test") #, size=(800,600))
		panel = wx.Panel(self)
#		vsizer = wx.BoxSizer(wx.VERTICAL)
		hsizer = wx.BoxSizer(wx.HORIZONTAL)
#		label = wx.StaticText(panel, -1, "Room:")
		lbutton = wx.Button(panel, -1, 'left')
		rbutton = wx.Button(panel, -1, 'right')
		self.testctl = MyScrollPanel(panel, size=(290,60))
		hsizer.Add(lbutton, 0, wx.EXPAND, 5)
		hsizer.Add(self.testctl, 1, wx.EXPAND, 5)
		hsizer.Add(rbutton, 0, wx.EXPAND, 5)
		panel.SetSizer(hsizer)
		lbutton.Bind(wx.EVT_BUTTON, self.OnLButton)
		rbutton.Bind(wx.EVT_BUTTON, self.OnRButton)
	def OnLButton(self, evt):
		self.testctl.Scroll(-1)
#		pos = self.testctl.offset
#		self.testctl.offset += 10
#		self.testctl.Refresh()
#		pos = self.testctl.GetScrollPos(wx.HORIZONTAL)
#		print 'OnLButton, pos =', pos
#		self.testctl.ScrollWindow(20, 0)
#		self.testctl.SetScrollPos(wx.HORIZONTAL, pos+10)
	def OnRButton(self, evt):
		self.testctl.Scroll(1)
#		pos = self.testctl.offset
#		self.testctl.offset -= 10
#		self.testctl.Refresh()
#		pos = self.testctl.GetScrollPos(wx.HORIZONTAL)
#		print 'OnRButton, pos =', pos
#		self.testctl.SetScrollPos(wx.HORIZONTAL, pos-10)
		

def main():
	app = wx.PySimpleApp()
	frame = MyFrame(None)
	frame.Show(True)
	app.MainLoop()
	
if __name__ == '__main__':
	main()
